<?php
MYDCONN();
$GLOBALS['MYT'] = $GLOBALS['MYD'];
form_pr('getProviders','','','post');
?>
<div class="title">Fornecedores <?php mn_field('button','ED','newProvider','Novo Fornecedor','','','','" onclick="Lib/'); ?> | 
	<?php mn_field('select','ED','CODE','',"SELECT CODE AS ID, name AS NAME
	  			FROM ccenter_contas",'','',''); ?> | <?php mn_field('hselect','ED','TYPE',2,"Interno;Externo#1;2",'','',''); ?> | <?php mn_field('select','ED','Status','',"SELECT Ref AS ID,name AS NAME
	  			FROM hcce_status",'','',''); ?> <input type="submit" name="Submit2" value="Consultar"></div>
<table width="98%"  border="0" cellpadding="3" cellspacing="1">
  <?php 
  if (!isset($_GET['Iv'])) { 
  
  echo '<tr bgcolor="#F2F2F2">
    <td>Numero</td>
    <td width="20%">Designação</td>
    <td width="20%">área do Fornecedor</td>
    <td width="10%">Tipo</td>
    <td width="10%">Estado</td>
    <td width="10%">Modificar</td>
	</tr>';
  
    $GET = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_providers.ref,
					ccenter_providers.name AS Description,
					ccenter_providers.NIF,
					ccenter_providers.TYPE,
					ccenter_providers.Status,
					ccenter_contas.name
				FROM ccenter_providers
				 LEFT OUTER JOIN ccenter_providerscodes ON ccenter_providerscodes.RefProvider = ccenter_providers.Ref
				 LEFT OUTER JOIN ccenter_contas ON ccenter_contas.CODE = ccenter_providerscodes.CODE
				 WHERE ccenter_providers.Status != 5
				 GROUP BY ccenter_providers.ref
				ORDER BY name ASC, Description ASC"); 
	for ($f = 1; $f <= $GET[0]; $f++) { 
	
	echo '<tr height="20" bgcolor="'.gridlines($f).'">
		<td><a href="?jB=4&Iv='.$GET[$f]['ref'].'">'.$GET[$f]['ref'].'</a></td>
		<td>'.$GET[$f]['Description'].'</td>
		<td>'.$GET[$f]['name'].'</td>
		<td>'.$GET[$f]['TYPE'].'</td>
		<td>'.$GET[$f]['Status'].'</td>
		<td></td>
		</tr>';
   }
  } else {
	echo '<tr bgcolor="#D3D6E4">
		<td colspan="5">^ Listagem de Fornecedores Minimizada | <a href="?jB=4">Maximizar (+)</a></td>
		</tr>';
  }?>
</table>
<?php if (isset($_GET['Iv']) && $_GET['Iv'] != '') { ?>
<br>
<table width="100%"  border="0" cellspacing="1" cellpadding="3">
  <?php
    $GET = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_providers.ref,
					ccenter_providers.name,
					ccenter_providers.Observations,
					ccenter_providers.TYPE,
					ccenter_providers.NIF
				FROM ccenter_providers
				WHERE ref = {$_GET['Iv']}
				ORDER BY name "); 
	for ($f = 1; $f <= $GET[0]; $f++) { 
	echo '<input value="'.$GET[$f]['ref'].'" name="Provider" type="hidden" id="Provider">'; ?>

  <tr bgcolor="#ACB1CC">
    <td colspan="5">Propriedades do Fornecedor </td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td width="21%">Fornecedor:</td>
    <td colspan="4"><input value="<?php echo $GET[$f]['name']?>" name="name" type="text" id="name" size="70"></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>ObservaÇ&otilde;es</td>
    <td><input name="Observations" type="text" id="Observations" value="<?php echo $GET[$f]['Observations']?>" size="40" maxlength="40"></td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>NIF:</td>
    <td width="33%"><input  value="<?php echo $GET[$f]['NIF']?>" name="Tax" type="text" id="Tax" size="24" maxlength="255"></td>
    <td width="20%">Tipo:
      <select name="TYPE" id="TYPE">
        <option value="2">Externo</option>
        <option value="1">Interno</option>
      </select></td>
    <td colspan="2">Estado: <?php mn_field('select','ED','Status',$List[$r]['StatRef'],"SELECT StatRef,name
	  			FROM hcce_status WHERE Type = 4",'','',''); ?></td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td colspan="5">&nbsp;</td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td colspan="5">Areas</td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td>CÓdigo</td>
    <td colspan="4">Descrição</td>
  </tr>
  <?php
    $CCOD = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_contas.CODE,
					ccenter_contas.name
				FROM ccenter_providerscodes 
				INNER JOIN ccenter_contas ON ccenter_contas.CODE = ccenter_providerscodes.CODE
				WHERE RefProvider = {$GET[$f]['ref']}
				ORDER BY name ASC"); 
	for ($r = 1; $r <= $CCOD[0]; $r++) { ?>
	<tr bgcolor="#FBFBFB">
    <td><?php echo $CCOD[$r]['CODE'];?></td>
    <td colspan="4"><?php echo $CCOD[$r]['name'];?></td>
  </tr>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td colspan="4">Contractos</td>
  </tr>
  <tr bgcolor="#FBFBFB">
    <td>&nbsp;</td>
    <td width="33%">Descrição</td>
    <td>Modo Pagamento</td>
    <td width="14%">Nº Cliente</td>
    <td width="12%">Estado</td>
  </tr>
    <?php
    $Contracts = $GLOBALS['MYD']->db_array("SELECT 
					 ccenter_contractos.Description,
					 ccenter_contractos.Client,
					 ccenter_contractos.PayMode,
					 ccenter_contractos.Status
				FROM ccenter_contractos 
				WHERE RefProvider = {$GET[$f]['ref']}
				AND CODE = {$CCOD[$r]['CODE']}"); 
	for ($s = 1; $s <= $Contracts[0]; $s++) { ?>
  <tr bgcolor="#FBFBFB">
    <td>&nbsp;</td>
    <td><?php echo $Contracts[$s]['Description'];?></td>
    <td><?php echo $Contracts[$s]['PayMode'];?></td>
    <td><?php echo $Contracts[$s]['Client'];?></td>
    <td><?php echo $Contracts[$s]['Status'];?></td>
  </tr>
  <?php } 
  } ?>
  <tr bgcolor="#F2F2F2">
    <td>&nbsp;</td>
    <td colspan="4"><input name="EditProvider" type="submit" id="EditProvider" value="Salvar AlteraÇ&otilde;es">
      <input name="RemProvider" type="submit" id="RemProvider" value="Remover"></td>
  </tr>
  <?php 
 }?>
</table>
<?php } ?>
</form>